<template>
  <div id="app">
    <h5>app组件</h5>
    <img alt="Vue logo" src="./assets/logo.png" />
    <!--    <HelloWorld msg="Welcome to Your Vue.js App"/>-->
    <p>父组件中userinfo.address的值也会变化:{{ userinfo.address }}</p>
    <!--:init表示是数字-->
    <Count :init="'6'" :username="username" :userinfo="userinfo"></Count>

    <Left></Left>
    <ArrayCom></ArrayCom>
    <!--动态组件-->

    <button @click="showRed">红色组件</button>
    <button @click="showBlue">蓝色组件</button>

    <!--不销毁，只缓存Red,include和exclude不能同时存在-->
    <keep-alive include="Red">
      <component :is="dynamicCom"></component>
    </keep-alive>
    <MySlot>
      <!--param为形参-->
      <template v-slot:s2="param">
        <!--指定插入哪个插槽，简写#s2-->
        <span>插入的内容</span>;<span>插入的内容2</span>;=<span>{{param.msg }}</span>
      </template>
      <!--解构赋值-->
      <template #s3="{ msg } ">
        <p>解构赋值:{{ msg.name }}</p>
      </template>
    </MySlot>
  </div>
</template>

<script>
// import HelloWorld from './components/HelloWorld.vue'
import Count from '@/components/Count.vue'
import Left from '@/components/Left.vue'
import ArrayCom from '@/components/ArrayCom.vue'
import Red from '@/components/Red.vue'
import Blue from '@/components/Blue.vue'
import MySlot from '@/components/MySlot.vue'

export default {
  name: 'App',
  data () {
    return {
      username: 'wangrui',
      userinfo: {
        age: 22,
        address: 'wuh'
      },
      dynamicCom: 'Blue' // 这里可以用组件名的字符串，也可以直接传组件对象:dynamicCom: Blue,但是如果写成对象形式，无法和include和exclude配合使用
    }
  },
  components: {
    Count,
    Left,
    ArrayCom,
    Red,
    Blue,
    MySlot
  },
  methods: {
    showRed () {
      this.dynamicCom = 'Red'
    },
    showBlue () {
      this.dynamicCom = 'Blue'
    }
  }
}
</script>

<style scoped>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
/*deep相当于scoped临时不生效*/
/deep/ h5 {
  color: red;
}
</style>
